﻿using System;
using com.yoozoo.gta.Extension.UGUI.Editor;
using com.yoozoo.gta.Extension.UGUI.ScreenOrientationEx;
using UnityEngine;
using UnityEngine.UI;
using Yoozoo.UI.YGUI;

namespace com.yoozoo.gta.Extension.UGUI.ScreenOrientation.Adapter
{
    [Serializable]
    public class YButtonAdapterConfig
    {
        public bool enableSetrAwScale; // 是否设置awScale
        [ReadOnlyAdapter] public bool shouldTween;
        [ReadOnlyAdapter] public Vector3 localScale;
        [ReadOnlyAdapter] public Selectable.Transition transition;

        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return false;
            }

            YButtonAdapterConfig other = (YButtonAdapterConfig) obj;
            if (shouldTween != other.shouldTween)
            {
                return false;
            }

            if (localScale != other.localScale)
            {
                return false;
            }

            if (enableSetrAwScale != other.enableSetrAwScale)
            {
                return false;
            }

            if (transition != other.transition)
                return false;
            return true;
        }

        public override int GetHashCode()
        {
            int hash = 17;
            hash = hash * 23 + shouldTween.GetHashCode();
            hash = hash * 23 + localScale.GetHashCode();
            hash = hash * 23 + enableSetrAwScale.GetHashCode();
            hash = hash * 23 + transition.GetHashCode();
            return hash;
        }
    }

    [DisallowMultipleComponent]
    public class YButtonAdapter : AdaptBase<YButtonAdapterConfig, YButton>
    {
        protected override void CopyProperty(YButtonAdapterConfig config)
        {
            base.CopyProperty(config);
            config.shouldTween = mComponent.GetScaleTweenInfo().shouldTween;
            config.localScale = mComponent.transform.localScale;
            config.transition = mComponent.transition;
        }

        protected override void ApplyConfig(YButtonAdapterConfig config)
        {
            base.ApplyConfig(config);
            if (config.shouldTween && config.enableSetrAwScale)
            {
                mComponent.SetrAwScale(config.localScale);
            }

            mComponent.transition = config.transition;
        }
    }
}